//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.zhiyume.controller;

import com.zhiyume.dao.entity.TActivity;
import com.zhiyume.dao.entity.TAdminSys;
import com.zhiyume.page.PageReq;
import com.zhiyume.service.TActivityService;
import com.zhiyume.service.common.ConstantEnum;
import com.zhiyume.service.util.JsonUtil;
import com.zhiyume.service.util.StringUtil;
import com.zhiyume.shiro.AdminSecurityManager;
import com.zhiyume.vo.CommonReqVO;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"/activity"})
public class ActivityController {
    @Autowired
    private TActivityService tActivityService;

    public ActivityController() {
    }

    @RequestMapping({"/findById"})
    @ResponseBody
    public Map findById(long id) {
        TActivity activity = this.tActivityService.findActivityById(id);
        return null == activity.getId() ? JsonUtil.returnResult(ConstantEnum.CONSTANT_MISS_PARA.getErrType(), ConstantEnum.CONSTANT_MISS_PARA.getErrMsg()) : JsonUtil.returnResult(ConstantEnum.CONSTANT_SUCCESS.getErrType(), ConstantEnum.CONSTANT_SUCCESS.getErrMsg(), activity);
    }

    @RequestMapping({"/addActivity"})
    @ResponseBody
    public Map addActivity(TActivity tActivity) {
        TActivity activity = new TActivity();
        String coverUrl = tActivity.getCoverUrl();
        if (StringUtil.isNotBlank(coverUrl) && coverUrl.contains("@@@@")) {
            String[] imgUrl = coverUrl.split("@@@@");
            tActivity.setCoverUrl(imgUrl[0]);
            tActivity.setContentUrl(imgUrl[1]);
        }

        TAdminSys sysUser = AdminSecurityManager.getSessionTAdminSys();
        tActivity.setCreatePerson(sysUser.getId() + "");
        tActivity.setIsShow(Integer.parseInt("0"));
        String errType = ConstantEnum.CONSTANT_SUCCESS.getErrType();
        String errMsg = ConstantEnum.CONSTANT_SUCCESS.getErrMsg();

        try {
            activity = this.tActivityService.addActivity(tActivity);
        } catch (Exception var8) {
            errType = ConstantEnum.CONSTANT_SYS_ERROR.getErrType();
            errMsg = var8.getMessage();
        }

        return JsonUtil.returnResult(errType, errMsg, activity);
    }

    @RequestMapping({"/activityListPage"})
    public ModelAndView activityListPage() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/activity/activityListPage");
        return modelAndView;
    }

    @RequestMapping({"/getActivityDataList"})
    @ResponseBody
    public Map<String, Object> getActivityDataList(CommonReqVO reqVO, PageReq page) {
        Map<String, Object> dataMap = new HashMap();
        this.activityData(reqVO, page, dataMap);
        return dataMap;
    }

    @RequestMapping({"/searchActivityList"})
    @ResponseBody
    public Map<String, Object> searchActivityList(CommonReqVO reqVO, PageReq page) {
        Map<String, Object> dataMap = new HashMap();
        this.activityData(reqVO, page, dataMap);
        return dataMap;
    }

    private void activityData(CommonReqVO reqVO, PageReq page, Map<String, Object> dataMap) {
        List<TActivity> list = this.tActivityService.queryActivityList(reqVO, page);
        list = list.size() > 0 ? list : null;
        int count = this.tActivityService.countActivity(reqVO);
        dataMap.put("list", list);
        dataMap.put("total", count);
        dataMap.put("page", page);
    }

    @RequestMapping({"/addActivityPage"})
    public ModelAndView addActivityPage(Model model) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/activity/activityAddPage");
        TActivity activity = new TActivity();
        activity.setShareNum(200 + (new Random()).nextInt(300));
        model.addAttribute("activity", activity);
        return modelAndView;
    }

    @RequestMapping({"/editActivityPage"})
    public ModelAndView editPersonPage(@RequestParam("id") long id, Model model) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/activity/activityEditPage");
        TActivity tActivity = this.tActivityService.findActivityById(id);
        model.addAttribute("activity", tActivity);
        return modelAndView;
    }

    @RequestMapping({"/updateActivity"})
    @ResponseBody
    public Map updateActivity(@ModelAttribute("form") TActivity tActivity) {
        String errType = ConstantEnum.CONSTANT_SUCCESS.getErrType();
        String errMsg = ConstantEnum.CONSTANT_SUCCESS.getErrMsg();

        try {
            this.tActivityService.updateActivity(tActivity);
        } catch (Exception var5) {
            errType = ConstantEnum.CONSTANT_SYS_ERROR.getErrType();
            errMsg = var5.getMessage();
        }

        return JsonUtil.returnResult(errType, errMsg);
    }

    @RequestMapping({"/deleteActivityById"})
    @ResponseBody
    public Map deleteActivity(long id) {
        String errType = ConstantEnum.CONSTANT_SUCCESS.getErrType();
        String errMsg = ConstantEnum.CONSTANT_SUCCESS.getErrMsg();

        try {
            this.tActivityService.deleteActivity(id);
        } catch (Exception var6) {
            errType = ConstantEnum.CONSTANT_SYS_ERROR.getErrType();
            errMsg = var6.getMessage();
        }

        return JsonUtil.returnResult(errType, errMsg);
    }

    @RequestMapping({"/publishActivity"})
    @ResponseBody
    public Map publishActivity(long id) {
        String errType = ConstantEnum.CONSTANT_SUCCESS.getErrType();
        String errMsg = ConstantEnum.CONSTANT_SUCCESS.getErrMsg();

        try {
            this.tActivityService.publishActivity(id);
        } catch (Exception var6) {
            errType = ConstantEnum.CONSTANT_SYS_ERROR.getErrType();
            errMsg = var6.getMessage();
        }

        return JsonUtil.returnResult(errType, errMsg);
    }

    @RequestMapping({"/refuseActivity"})
    @ResponseBody
    public Map refuseActivity(long id) {
        String errType = ConstantEnum.CONSTANT_SUCCESS.getErrType();
        String errMsg = ConstantEnum.CONSTANT_SUCCESS.getErrMsg();

        try {
            this.tActivityService.refuseActivity(id);
        } catch (Exception var6) {
            errType = ConstantEnum.CONSTANT_SYS_ERROR.getErrType();
            errMsg = var6.getMessage();
        }

        return JsonUtil.returnResult(errType, errMsg);
    }

    @RequestMapping({"/underOrUpActivity"})
    @ResponseBody
    public Map underOrUpActivity(long id, int isShow) {
        String errType = ConstantEnum.CONSTANT_SUCCESS.getErrType();
        String errMsg = ConstantEnum.CONSTANT_SUCCESS.getErrMsg();

        try {
            this.tActivityService.underOrUpActivity(id, isShow);
        } catch (Exception var7) {
            errType = ConstantEnum.CONSTANT_SYS_ERROR.getErrType();
            errMsg = var7.getMessage();
        }

        return JsonUtil.returnResult(errType, errMsg);
    }
}
